package com.leyou.auth.config;

import com.leyou.common.auth.utils.RsaUtils;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.security.PrivateKey;
import java.security.PublicKey;

/**
 * User: ycs
 * Date: 2020/8/30
 * Time: 16:58
 *
 * @author: ycs
 * Description: No Description
 */
@Data
@ConfigurationProperties("ly.jwt")
public class JwtProperties {
    private String pubKeyPath;
    private String priKeyPath;
    private PrivateKey privateKey;
    private PublicKey publicKey;
    private Cookie cookie = new Cookie();
    private AppTokenPojo app = new AppTokenPojo();

    @Data
    public class Cookie {
        private Integer expire;
        private Integer refreshTime;
        private String cookieName;
        private String cookieDomain;
    }

    //类实例化之前执行
    @PostConstruct
    public void intoMethod() throws Exception {
        this.privateKey = RsaUtils.getPrivateKey(priKeyPath);
        this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
    }

    @Data
    public class AppTokenPojo {
        private Integer expire;
        private Long id;
        private String serviceName;
    }

}
